<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\admin\controller;
use \think\Controller;
use think\Request;

class Common extends Controller{
    //初始化方法
    public function _initialize()
    {
        //验证是否登录状态，访问身份是否合法
        if(!session("id")||!session("username")){
            $this->error("用户身份不合法，请重新登录",'login/index');
        }







        //规则认证
        $auth=new Auth();
        $request=Request::instance();
        $con=$request->controller();//获取当前控制器
        $action=$request->action();//获取当前方法
        $name=$con."/".$action;
        $notCheck=array('Index/index','Login/logout');
        if(session("id")!=1){
            if(!in_array($name,$notCheck)){
                if(!$auth->check($name,session('id'))){
                    $this->error("没有权限",url('index/index'));
                }
            }
        }
    }
}